package org.jeecg.modules.iot.mqtt.server.service.processor.carOperate;

import org.jeecg.modules.iot.jtt808.JTT808Encoder;
import org.jeecg.modules.iot.jtt808.JTT808Message;
import org.jeecg.modules.iot.mqtt.entity.Packet;
import org.jeecg.modules.iot.model.Jt808Control.Jt808CentralControlConfig;
import org.jeecg.modules.iot.model.modbus.ModbusParams;
import org.jeecg.modules.iot.mqtt.server.service.processor.JT808MessageGenerator;
import org.jeecg.modules.iot.mqtt.server.service.processor.MessageType;
import org.springframework.stereotype.Component;

import static org.jeecg.modules.iot.utils.JT808Utils.bytesToHexString;
@Component
public class DefenseCarMessageGenerator implements JT808MessageGenerator {
    @Override
    public String generateMessage(JTT808Message message) {
        byte controlCommand = (byte) 0x00; // 车辆控制指令，例如熄火指令
        byte controlParameter = 0x01; // 设防
        message.packetCount = 0; // 设置分包总数，如果消息体超过1024字节需要分包发送
        message.packetIndex = 0; // 设置分包索引，表示当前分包的序号
        message.id=0x8500;
        Packet p = Packet.create(2);
        p.addByte(controlCommand);
        p.addByte(controlParameter);
        message.body = p.getBytes();
        return bytesToHexString(JTT808Encoder.encode(message));
    }

    @Override
    public String generateMessage(JTT808Message message, Jt808CentralControlConfig config) {
        return "";
    }

    @Override
    public String generateMessage(JTT808Message message, ModbusParams params) {
        return "";
    }


    @Override
    public String getType() {
        return MessageType.DEFENSE_CAR.name();
    }
}
